package cc.togetherit.jcrawler.dataPool;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.TimeUnit;

public class  MemPool<T> implements CrawlerPool<T> {
    private static final int defaultAwaintTime = 6;
    public static final int defaultMaxSize = 800000;
    private ArrayBlockingQueue<T> pool;
    
    public MemPool(int maxSize) {
        this.pool = new ArrayBlockingQueue<T>(maxSize);
    }

    public  T consume() {
        try {
            return pool.poll(defaultAwaintTime, TimeUnit.SECONDS);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return null;
    }

    public  boolean produce(T data) {
         try {
            return pool.offer(data, defaultAwaintTime, TimeUnit.SECONDS);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
         return false;
    }

    

}
